//
//  NetRewardViewController.m
//  jingjing2.0
//
//  Created by apple on 16/5/25.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "NetRewardViewController.h"

@interface NetRewardViewController ()

@end

@implementation NetRewardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.name.text=_prizeTitle;
    self.rewardBtn.layer.cornerRadius=4;
    self.rewardBtn.clipsToBounds=YES;
    self.title=@"流量包领取";
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [GeneralTool hideTabBar];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [GeneralTool showTabBar];
}

- (IBAction)getReward:(id)sender
{
    [self.phoneNum resignFirstResponder];
    //http://192.168.1.107:3722/Activity/ColorEggsSubmitFlow
    //m_ColorEggsSubmitFlowPara(UserCode,GetNoteID,Mobile,Timestamp,Sign)
    if (self.phoneNum.text.length==0) {
        [MBProgressHUD showError:@"请输入手机号再领取"];
        [self.phoneNum becomeFirstResponder];
    }else if ([GeneralTool valiMobile:self.phoneNum.text]!=nil)
    {
        [MBProgressHUD showError:[GeneralTool valiMobile:self.phoneNum.text]];
    }else{
        NSString *timeStamp=[GeneralTool gettimestamp];
        NSString *noteID=[NSString stringWithFormat:@"%ld",_noteId];
        NSDictionary *dic=@{@"UserCode":GETUSERCODE,
                            @"GetNoteID":noteID,
                            @"Mobile":self.phoneNum.text,
                            @"Timestamp":timeStamp,
                            };
        NSString *sign=[GeneralTool GetSin:dic];
        NSDictionary *dataDic=@{@"UserCode":GETUSERCODE,
                                @"GetNoteID":noteID,
                                @"Mobile":self.phoneNum.text,
                                @"Timestamp":timeStamp,
                                @"Sign":sign};
        NSDictionary *requestDic=@{@"m_ColorEggsSubmitFlowPara":dataDic};
        [RequestTool requestDataWithType:@"post" andUrlString:@"Activity/ColorEggsSubmitFlow" andParameters:requestDic andRequestFinished:^(id responses, NSError *error) {
            if (error)
            {
                [MBProgressHUD showError:@"提交失败，请稍后再试"];
            }
            if ([responses[@"IsSuccess"]integerValue]==1) {
                [MBProgressHUD showSuccess:responses[@"ReturnObject"]];
                [self.navigationController popViewControllerAnimated:YES];
            }else
            {
                [MBProgressHUD showSuccess:responses[@"ReturnObject"]];
            }
        }];
    }

}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
     [self.view endEditing:YES];
}
@end
